package com.basin.micro.auth.module.sign.controller;

import com.basin.common.core.response.ResponseResult;
import com.basin.micro.auth.module.sign.pojo.enums.PlatformEnum;
import com.basin.micro.auth.module.sign.strategy.login.LoginContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Locale;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/auth")
public class AuthController {
    private final LoginContext loginContext;

    @PostMapping("/login")
    public ResponseResult<String> login(@RequestParam(name = "platform") String platform,
                                        @RequestParam(name = "loginType") String loginType,
                                        @RequestBody Object body) {
        PlatformEnum platformEnum = PlatformEnum.valueOf(platform.toUpperCase(Locale.ROOT));
        String token = loginContext.doLogin(platformEnum, loginType, body);
        return ResponseResult.success(token);
    }
}
